package com.shujia.scala;

import scala.Int;

import java.io.BufferedReader;
import java.io.FileReader;
import java.util.HashMap;

public class Demo19JavaWordCount {
    public static void main(String[] args) throws Exception {


        //使用hashmapb凹槽最终的结果
        HashMap<String, Integer> countMap = new HashMap<>();


        //1、读取文件
        BufferedReader reader = new BufferedReader(new FileReader("scala/data/words.txt"));

        String line;

        while ((line = reader.readLine()) != null) {

            String[] words = line.split(",");

            for (String word : words) {


                //如果在hashmap存在这个 单词直接加一，如果不存在，存一个一进去
                if (countMap.containsKey(word)) {
                    Integer integer = countMap.get(word);
                    countMap.put(word, integer + 1);
                } else {
                    countMap.put(word, 1);
                }

            }

        }
        System.out.println(countMap);


    }
}
